//
//  CommentCell.m
//  qiuShiJiangHu
//
//  Created by xalo on 16/1/27.
//  Copyright © 2016年 糗事江湖项目组. All rights reserved.
//

#import "CommentCell.h"
#import "CommentModel.h"

#import "UIImageView+WebCache.h"



@interface CommentCell ()

@property (strong, nonatomic) IBOutlet UILabel *supportLabel;

@property (strong, nonatomic) IBOutlet UILabel *oppositionLabel;

@end



@implementation CommentCell

- (IBAction)clickSupportButton:(UIButton *)sender {

    NSInteger number = [self.supportLabel.text integerValue];
    
    number++;
    
    self.supportLabel.text = [NSString stringWithFormat:@"%ld",number];

}



- (IBAction)clickOppositionButton:(UIButton *)sender {

    NSInteger number = [self.oppositionLabel.text integerValue];
    
    number++;
    
    self.oppositionLabel.text = [NSString stringWithFormat:@"%ld",number]; 
    
}




















-(void)setContentWithModel:(CommentModel *)model
{
    
    NSInteger number = [model.user[@"id"] integerValue];
    
    NSString *numStr = [NSString stringWithFormat:@"%ld",number];
    
    NSString *num1 = nil;
    
    if (numStr.length == 8) {
        
        num1 = [numStr substringWithRange:NSMakeRange(0, 4)];
        
    }else if(numStr.length == 7)
    {
        num1 = [numStr substringWithRange:NSMakeRange(0, 3)];
        
    }else if(numStr.length == 6)
    {
        num1 = [numStr substringWithRange:NSMakeRange(0, 2)];
        
    }else
    {
        num1 = [numStr substringWithRange:NSMakeRange(0, 1)];
        
    }
    NSString *url = [NSString stringWithFormat:@"http://pic.qiushibaike.com/system/avtnew/%@/%@/thumb/%@",num1,numStr,model.user[@"icon"]];
    
    [self.iconImage sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"Icon@2x"]];
    
    self.iconImage.layer.cornerRadius = 15;
    
    self.iconImage.layer.masksToBounds = YES;

    self.loginLabel.text=model.user[@"login"];
    self.contentLabel.text=model.content;
    
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
